package com.example.mobile20339zwl0408;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView textView;
    private CheckBox cheyinqing;
    private CheckBox cheboli;
    private CheckBox chefangxiangpan;
    private Button anniu1;
    private TextView gouwuche;
    private TextView xuanzhong;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        cheyinqing.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    xuanzhong.setText("选中："+buttonView.getText().toString());
                }else {
                    xuanzhong.setText("取消选中："+buttonView.getText().toString());
                }
            }
        });

        cheboli.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    xuanzhong.setText("选中："+buttonView.getText().toString());
                }else {
                    xuanzhong.setText("取消选中："+buttonView.getText().toString());
                }
            }
        });


        chefangxiangpan.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked){
                    xuanzhong.setText("选中："+buttonView.getText().toString());
                }else {
                    xuanzhong.setText("取消选中："+buttonView.getText().toString());
                }
            }
        });

        anniu1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String msg="选中：";
                if (cheyinqing.isChecked()){
                    msg+="\n"+cheyinqing.getText().toString();
                }if (cheboli.isChecked()){
                    msg+="\n"+cheboli.getText().toString();
                }if (chefangxiangpan.isChecked()){
                    msg+="\n"+chefangxiangpan.getText().toString();
                }

                xuanzhong.setText(msg);
            }
        });





    }

    private void initView() {
        textView = (TextView) findViewById(R.id.textView);
        cheyinqing = (CheckBox) findViewById(R.id.cheyinqing);
        cheboli = (CheckBox) findViewById(R.id.cheboli);
        chefangxiangpan = (CheckBox) findViewById(R.id.chefangxiangpan);
        anniu1 = (Button) findViewById(R.id.anniu1);
        gouwuche = (TextView) findViewById(R.id.gouwuche);
        xuanzhong = (TextView) findViewById(R.id.xuanzhong);
    }
}